﻿using MediatR;
using SlaughterItem.Common.Domains.Log;
using SlaughterItem.Common.Dtos;
using SlaughterItem.Common.Infrastructures.Interfaces;
using SlaughterItem.Enum;

namespace SlaughterItem.API.Application.Commands.Week02.Log
{
    public class ShowLogDataHandler : IRequestHandler<ShowLogDataCommand, Result>
    {
        public ShowLogDataHandler(IBaseRepository<LogData> logDataRepository)
        {
            LogDataRepository = logDataRepository;
        }
        public IBaseRepository<LogData> LogDataRepository { get; set; }
        public async Task<Result> Handle(ShowLogDataCommand request, CancellationToken cancellationToken)
        {
            var result=new Result() { Code=(int)CommonErrorCode.Search};
            var list=LogDataRepository.GetAll().ToList();
            if (list != null)
            {
                result.Data = list;
                result.Code = (int)CommonErrorCode.Success;
                return result;
            }
            else
            { 
                return result;
            }
        }
    }
}
